import threading
from yoloService.yosDispatcher import yosDispatcher
import torch
import time
yos=yosDispatcher()

class imgDetectThread(threading.Thread):

    def __init__(self,model,device,half,conf_thres,imgInfoMap):
        threading.Thread.__init__(self)
        self.imgInfoMap=imgInfoMap
        self.model=model
        self.device=device
        self.half=half
        self.th=conf_thres
        self.result=None

    def run(self):
        print("新线程运行.."+self.imgInfoMap["savedPath"])
        with torch.no_grad():
            self.result = yos.detect(model=self.model, device=self.device, half=self.half, ImgPath=self.imgInfoMap["savedPath"],
                                outPath=self.imgInfoMap["outPath"], conf_thres=self.th,imgInfoMap=self.imgInfoMap)

    def getDetectResult(self):
        #加入没有结果，则登台一会
        while(self.result==None):
            time.sleep(5)
        return self.result